package com.zhaungjie.base.utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 数据库数组序列化程序
 *
 * @author zhuangjie
 * @date 2023/10/12
 */
public class ArraySerializeForDB {
    private static final String SEPARATOR = ",";
    public static String serialize(List<String> list) {
        if (list == null || list.size() == 0) {
            return "";
        }
        return String.join(SEPARATOR,list);
    }

    public static List<String> deserialize(String ... stringArr) {
        if (stringArr == null || stringArr.length == 0) {
            return new ArrayList<>();
        }
        String joinStr = String.join(SEPARATOR, stringArr).replaceAll("^("+SEPARATOR+"*)|("+SEPARATOR+"*)$", "").trim();
        return Arrays.asList(joinStr.split(SEPARATOR));
    }
}
